#include <iostream>
#include "parser.h"
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <string>

void Parser::initialize() { 
    i = 0;
    c = 0;
	HALT = false;
}

void Parser::ignoreBlank(char TabChar[], int idxAwal, int& idxAkhir) {//prosedur untuk meng-ignore spasi
	int i = idxAwal;
	while ((TabChar[i] != '\0') && (TabChar[i] == ' ')) {
		i++;
		}
	idxAkhir = i;
	}
	

char* Parser::getString() {
   return tabparser;
}	 
	 
Parser::Parser() {
	init = false;//bakalan jadi true kalo udah ada operasi new
	i = 0;
	c = 0;
}

Parser::~Parser() {
	if(init==true) {
		delete aplayer;
		delete afield;
		delete ashop;
		delete akurcharvest;
		delete akurcwater;
		delete akurcslash;
	}
        system("cls");
        gotoxy(0,18); cout << "mengakhiri permainan" << endl;
}

bool Parser::getHALT() const {
	return HALT;
}

void Parser::getInput() {
    c = getch();
    if (c==224 && init==true) {
		gScan = getch();
		switch(gScan) {
			case 72://panah atas
				if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
					if((aplayer->getpos()).y > 0)
						aplayer->moveUp();
					else
						aplayer->turn_up();
				}else if(aplayer->getArea()==1) {//jika lahan
					if(aplayer->getFace()!=2){
						aplayer->turn_up();
					}else{
						if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
							if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
								aplayer->moveUp();
							}
						}
					}
				}
				break;
			case 80://panah bawah
				if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
					if((aplayer->getpos()).y < 5) {
						aplayer->moveDown();
					}else{
						aplayer->turn_down();
					}
				}else if(aplayer->getArea()==1){
					if(aplayer->getFace()!=3){
						aplayer->turn_down();
					}else{
						if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
							if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
								aplayer->moveDown();
							}
						}
					}
				}
				break;
			case 75://panah kiri
				if(aplayer->getArea()==0 || aplayer->getArea()==2) {
					if((aplayer->getpos()).x > 0) {
						aplayer->moveLeft();
					}else{
						aplayer->turn_left();
					}
				}else if(aplayer->getArea()==1) {
					if(aplayer->getFace()!=0){
						aplayer->turn_left();
					}else{
						if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
							if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
								aplayer->moveLeft();
							}
						}
					}
				}
				break;
			case 77://panah kanan
				if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
					if((aplayer->getpos()).x < 5){
						aplayer->moveRight();
					}else{
						aplayer->turn_right();
					}
				}else if(aplayer->getArea()==1){
					if(aplayer->getFace()!=1){
						aplayer->turn_right();
					}else{
						if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
							if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
								aplayer->moveRight();
							}
						}
					}
				}
				break;
		}
		
		if(aplayer->getArea()==0) {//rumah
			ahouse->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),0,0,0,0,0,0,0,0,0); printStatus();
		}else if(aplayer->getArea()==1){//lahan
			//afield->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),akurcharvest->GetX(),akurcharvest->GetY(),akurcharvest->getFace(),akurcwater->GetX(),akurcwater->GetY(),akurcwater->getFace(),akurcslash->GetX(),akurcslash->GetY(),akurcslash->getFace());
			akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
			akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
			akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
			afield->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),akurcharvest->GetX(),akurcharvest->GetY(),akurcharvest->getFace(),akurcwater->GetX(),akurcwater->GetY(),akurcwater->getFace(),akurcslash->GetX(),akurcslash->GetY(),akurcslash->getFace()); printStatus();
			//cout << "tes : " << akurcwater->getFace() << " " << akurcwater->GetX() << " " << akurcwater->GetY() << endl;
		}else if(aplayer->getArea()==2){//toko
			ashop->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),0,0,0,0,0,0,0,0,0); printStatus();
		}
		//cout << akurcwater->NearestPoint(afield).x << " " << akurcwater->NearestPoint(afield).y << endl;
		//cout << akurcharvest->NearestPoint(afield).x << " " << akurcharvest->NearestPoint(afield).y << endl;
		//cout << akurcslash->NearestPoint(afield).x << " " << akurcslash->NearestPoint(afield).y << endl;
	}else{
        while (c != 13) {
              if (c == 8) {
                    cout<<"\b \b";
                    c = getch();
					if (i>0) {
					i--;
					}
                    }
              else {
			tabparser[i] = (char) c;
			std::cout<<(char) c;
			c = getch();
			i++;
        }
        }
        if (c == 13) {
			tabparser[i] = '\0';
			cout << endl;
        }
		//------- proses perintah
		int k=0;
		int m;
		int z = 0;
		char command[100];
		ignoreBlank(tabparser, k, m);
		while((tabparser[m]!=' ') && (tabparser[m]!='#') && (tabparser[m]!='\0')) {
			command[z] = tabparser[m];
			m++;
			z++;
		}
		command[z] = '\0';
		if(init==false && (strcmp(command,"new")!=0 && strcmp(command,"load")!=0 && strcmp(command,"exit")!=0)) {
                    //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                    /*gotoxy(0,18);*/ cout << "Perintah yang Anda masukkan belum valid! new atau load untuk memulai permainan, exit untuk keluar dari permainan" << endl;
                    //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
		}else {
			z = 0;
			if(strcmp(command,"new")==0) {
				char param1[100];
				ignoreBlank(tabparser, m, m);
				while (tabparser[m] != ' ' && tabparser[m] != '#' && tabparser[m] != '\0') {
					param1[z] = tabparser[m];
					z++;
					m++;
					}
				param1[z] = '\0';
				if (z==0) {
                                    //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                    /*gotoxy(0,18);*/ cout<<"Memulai game gagal! Nama pemain belum dimasukkan!"<<endl;
                                    //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					ignoreBlank(tabparser, m, m);
					string string_param1(param1);
					if (tabparser[m] != '#') {
                                            //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                            /*gotoxy(0,18);*/ cout<<"Error! Kalimat input tidak diakhiri dengan pagar atau nama pemain lebih dari satu kata!"<<endl;
                                            //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }else {
						if(string_param1.length()>0 && init==false) {//bukan string kosong dan belom memulai game(init masih false)
							try {
								New(string_param1);
								init = true;
							}catch(int x){
								if(x==0){
                                                                    //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                                                    /*gotoxy(0,18);*/ cout << "Data dengan nama tersebut sudah ada sebelumnya . . " << endl;
                                                                    //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
								}
							}
						}else if(init==true) {
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout << "permainan sudah dimulai, silahkan exit terlebih dahulu" << endl;
                                                    gotoxy(0,17); cout<< ">\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					}
				}
			}else if(strcmp(command,"load")==0){
				z = 0;
				char param1[100];
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '#') {
                                    //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                    /*gotoxy(0,18);*/ cout<<"error! parameter berupa nama file yang ingin di-load belum dimasukkan! Silakan ulangi masukkan!"<<endl;
                                    //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else {
					while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
						param1[z] = tabparser[m];
						z++;
						m++;
					}
					ignoreBlank(tabparser, m, m);
					if (tabparser[m] == '\0') {
                                            //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                            /*gotoxy(0,18);*/ cout<<"komando load harus diakhiri dengan tanda pagar!"<<endl;
                                            //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}else if (tabparser[m] != '#') {
                                                //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
						cout<<"komando load harus memiliki hanya satu parameter yaitu nama file! Tidak boleh lebih!"<<endl;
                                                //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }else {
						//eksekusi komando load
						param1[z]='\0';
						string string_param1(param1);
						if (string_param1.length()>0 && init == false) {
							try{
								Load(string_param1);
								init = true;
							}catch(int e){
								if(e==0) {
                                                                    //gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t";
                                                                    /*gotoxy(0,18);*/ cout << "file tidak ada atau tidak bisa dibuka" << endl;
                                                                    //gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
								}
							}
						}else{
                                                        gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
							gotoxy(0,18); cout << "permainan sudah dimulai, silahkan exit terlebih dahulu" << endl;
                                                        gotoxy(0,17); cout<< ">\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
						}
					}
				} 
			}else if(strcmp(command,"exit")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"Komando salah! exit tidak dapat dilakukan. Pastikan input diakhiri dengan tanda pagar"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else {
					HALT = true;
				}
    		}else if(strcmp(command,"teleport")==0) {
				char param1[100];
				//sscanf(tabparser,"teleport %s #",param1);
				ignoreBlank(tabparser, m, m);
				z = 0;
				while ((tabparser[m] != '\0') && (tabparser[m] != ' ')) {
					param1[z] = tabparser[m];
					m++;
					z++;
				}
				param1[z] = '\0';
				string string_param1(param1);
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"error! destination teleport lebih dari satu atau input tidak diakhiri dengan pagar!"<<endl;
                                    gotoxy(0,17); cout<< ">\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else{
					if(string_param1=="rumah") {//rumah hanya bisa diakses dari lahan!!!
						if(aplayer->getArea()==1 || aplayer->getArea()==0){
							aplayer->setArea(0);
							aplayer->setpos(0,0);
							aplayer->setFace(3);
                                                        gotoxy(0,0);
                                                        for(int i = 1; i <= 16; i++)
                                                            cout<< "\t\t\t\t\t\t\t\n";
							ahouse->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),10,10,3,11,11,3,12,12,3); printStatus();
							akurcharvest->setpos(10,0);
							akurcharvest->setFace(3);
							akurcharvest->Sleep();
							akurcwater->setpos(11,0);
							akurcwater->setFace(3);
							akurcwater->Sleep();
							akurcslash->setpos(12,0);
							akurcslash->setFace(3);
							akurcslash->Sleep();
						}else{
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout << "teleport tidak dilakukan. rumah hanya bisa diakses dari lahan" << endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					}else if(string_param1=="lahan") {//lahan bisa diakses dari rumah dan toko
						if(aplayer->getArea()==0 || aplayer->getArea()==2 || aplayer->getArea()==1) {
							aplayer->setArea(1);
							aplayer->setpos(0,0);
							aplayer->setFace(3);
							//INISIALISASI kurcaci JANGAN LUPA!!
                                                        gotoxy(0,0);
                                                        for(int i = 0; i <= 16; i++)
                                                            cout<< "\t\t\t\t\t\t\t\n";
							afield->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),akurcharvest->GetX(),akurcharvest->GetY(),akurcharvest->getFace(),akurcwater->GetX(),akurcwater->GetY(),akurcwater->getFace(),akurcslash->GetX(),akurcslash->GetY(),akurcslash->getFace()); printStatus();
						}else{
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout << "teleport tidak dilakukan. lahan hanya bisa diakses dari lahan" << endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					}else if(string_param1=="toko") {//toko bisa diakses hanya dari lahan
						if(aplayer->getArea()==1  || aplayer->getArea()==2) {
							aplayer->setArea(2);
							aplayer->setpos(0,0);
							aplayer->setFace(3);
                                                        gotoxy(0,0);
                                                        for(int i = 1; i <= 16; i++)
                                                            cout<< "\t\t\t\t\t\t\t\n";
							ashop->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),0,0,0,0,0,0,0,0,0); printStatus();
							akurcharvest->setpos(10,0);
							akurcharvest->setFace(3);
							akurcharvest->Sleep();
							akurcwater->setpos(11,0);
							akurcwater->setFace(3);
							akurcwater->Sleep();
							akurcslash->setpos(12,0);
							akurcslash->setFace(3);
							akurcslash->Sleep();
						}else{
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout << "teleport tidak dilakukan. rumah hanya bisa diakses dari lahan" << endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					} else if(string_param1=="-help") {
                                            gotoxy(0,25); cout<< "\t\t\t\t\t\t\t\t";
                                            gotoxy(0,25);
						cout<<"-----------------Petunjuk Melakukan Teleport-----------------"<<endl;
						cout<<"Game ini memiliki tiga field utama, yaitu rumah, lahan, dan toko"<<endl;
						cout<<"Area teleport yang bisa diakses dari rumah hanyalah lahan"<<endl;
						cout<<"Area teleport yang bisa diakses dari lahan hanyalah rumah dan toko"<<endl;
						cout<<"Area teleport yang bisa diakses dari toko hanyalah lahan"<<endl;
						cout<<"Silakan masukkan komando teleport dengan mengetikkan : teleport <lahan|rumah|toko> #"<<endl;
						cout<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}else{
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "tidak ada tempat bernama " << string_param1 << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
				}	
			}else if(strcmp(command,"plow")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"Komando salah! Plow tidak dapat dilakukan. Pastikan input diakhiri dengan tanda pagar"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else {
					if(aplayer->getArea()==1 && afield->IsPlowable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
						aplayer->plow(afield);
						afield->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),akurcharvest->GetX(),akurcharvest->GetY(),akurcharvest->getFace(),akurcwater->GetX(),akurcwater->GetY(),akurcwater->getFace(),akurcslash->GetX(),akurcslash->GetY(),akurcslash->getFace()); printStatus();
					}else{
						gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
						gotoxy(0,18); cout<<"plow gagal! Pastikan area didepan Anda memenuhi syarat untuk di-plow!"<<endl;
						gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}
			}else if(strcmp(command,"inventory")==0) {
				ignoreBlank(tabparser, m, m);
				if(tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout <<"Komando salah! perintah inventory tidak dapat dilakukan. Pastikan input diakhiri dengan tanda pagar"<< endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else{
					aplayer->displayInventory();
				}
			}else if(strcmp(command,"put")==0) {
				int nslot;
				int zzz=0;
				int jumlah;
				char param1[10];
				char param2[10];
				ignoreBlank(tabparser, m, m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param1[z] = tabparser[m];
					m++;
					z++;
				}
				if (z != 0) {
					zzz++;
				}
				param1[z] = '\0';
				ignoreBlank(tabparser,m , m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param2[z] = tabparser[m];
					m++;
					z++;
				}
				if (z != 0) {
					zzz++;
				}
				param2[z] = '\0';
				ignoreBlank(tabparser, m, m);
				if ((tabparser[m] != '#') || (zzz<2)) {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18);cout<<"komando put harus diakhiri dengan tanda pagar dan harus memiliki tepat dua parameter!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					sscanf(param1,"%d",&nslot); // nomor slot di inventory yang ingin dijual
					sscanf(param2,"%d",&jumlah); // jumlah barang yang ingin dijual
					aplayer->put(nslot,jumlah,afield);
				} 
			}else if(strcmp(command,"slash")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando slash harus diakhiri dengan tanda pagar dan tidak boleh memiliki parameter lain! komando tidak bisa dieksekusi!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else {
					if(aplayer->getArea()==1) {//jika di lahan
						aplayer->slash(afield);
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "gagal sabit" << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
				}
			}else if(strcmp(command,"water")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18);cout<<"komando water harus diakhiri dengan tanda pagar dan tidak boleh memiliki parameter lain! komando tidak bisa dieksekusi!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else{
					if(aplayer->getArea()==1) {//hanya bisa di lahan
						aplayer->water(afield);
						afield->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),akurcharvest->GetX(),akurcharvest->GetY(),akurcharvest->getFace(),akurcwater->GetX(),akurcwater->GetY(),akurcwater->getFace(),akurcslash->GetX(),akurcslash->GetY(),akurcslash->getFace()); printStatus();
					}else{
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "gagal siram" << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}                				
			}else if(strcmp(command,"harvest")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando harvest harus diakhiri dengan tanda pagar dan tidak boleh memiliki parameter lain! komando tidak bisa dieksekusi!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else{
					if(aplayer->getArea()==1) {//jika lahan 
						aplayer->harvest(afield);
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "gagal panen" << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}
			}else if(strcmp(command,"wake_up")==0) {
				char param1[10];
				int nomor;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"Error! komando wake_up harus disertai dengan parameter yaitu nomor kurcaci!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					z = 0;
					while ((tabparser[m] != ' ') && (tabparser[m] != '#') && (tabparser[m] != '\0')) {
						param1[z] = tabparser[m];
						m++;
						z++;
					}
					param1[z] = '\0';
					ignoreBlank(tabparser, m, m);
					if (tabparser[m] != '#') {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"Error! komando wake_up kurcaci tidak boleh memiliki parameter lain selain nomor kurcaci dan harus diakhiri dengan tanda pagar!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }else {
						sscanf(param1,"%d",&nomor);
						//eksekusi wake_up kurcaci
						if(aplayer->getArea()==1) {//jika di lahan
							if(nomor==1) {
								akurcwater->Wake();
								cout << endl;
							}else if(nomor==2){
								akurcharvest->Wake();
								cout << endl;
							}else if(nomor==3) {
								akurcslash->Wake();
								cout << endl;
							}else{
                                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                            gotoxy(0,18); cout << "Error! tidak ada kurcaci dengan nomor tersebut !" << endl;
                                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                        }
						}else{
                                                        gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
							gotoxy(0,18); cout << "Error! komando wake_up kurcaci hanya bisa dipakai di lahan" << endl;
                                                        gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					}
				}
			}else if(strcmp(command,"sleep")==0) {
				char param1[10];
				int nkurc;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
					int n=m+1;
					ignoreBlank(tabparser, n, n);
					if (tabparser[n] == '#') {
						cout << tabparser[n] << endl;
						if ((tabparser[m] != '1') && (tabparser[m] != '2') && (tabparser[m] != '3')) {
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout<<"Komando untuk menidurkan kurcaci harus diikuti oleh nomor kurcaci yang valid, yaitu 1, 2, atau 3!"<<endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }else {
							z = 0;
							param1[z] = tabparser[m];
							sscanf(param1,"%d",&nkurc);
							//eksekusi kode membangunkan kurcaci
							if(aplayer->getArea()==1) {//jika di lahan
								if(nkurc==1) {
									akurcwater->Sleep();
								}else if(nkurc==2) {
									akurcharvest->Sleep();
								}else if(nkurc==3) {
									akurcslash->Sleep();
								}else {
                                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                                    gotoxy(0,18); cout << "Error! tidak ada kurcaci dengan nomor tersebut !" << endl;
                                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                                }
							}else{
                                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                            gotoxy(0,18); cout << "perintah sleep <nomor_kurcaci> hanya bisa dilakukan di lahan " << endl;
                                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                        }
						}
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"Error! Komando sleep untuk tidur player harus berupa 'sleep #' dan untuk menidurkan kurcaci harus berupa 'sleep <no.kurc> #'."<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
				}else {
					if(aplayer->getArea()==0) {//jika sedang di rumah
						aplayer->sleep();
					}else{
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"Sleep hanya bisa dilakukan di rumah!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}
			}else if(strcmp(command,"status")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
					cout<<"permintaan untuk melihat status harus diakhiri dengan tanda pagar dan tidak boleh memiliki parameter lain!"<<endl;
				}else{
					if(aplayer->getArea()==1) {//jika di lahan
						cout << "Kurcaci 1(water) ";
						if (akurcwater->isSleep())
							cout << "sleep" << endl;
						else
							cout << "wake_up" << endl;
						cout << "Kurcaci 2(harvest) ";
						if (akurcharvest->isSleep())
							cout << "sleep" << endl;
						else
							cout << "wake_up" << endl;
						cout << "Kurcaci 3(slash) ";
						if (akurcslash->isSleep())
							cout << "sleep" << endl;
						else
							cout << "wake_up" << endl;
						cout << endl;
					}else{
						cout << "perintah status hanya bisa dipakai di lahan" << endl;
					}
				}
			}else if(strcmp(command,"save")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando meng-save program harus diakhiri dengan tanda pagar dan tidak boleh memiliki parameter lain!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else{
					if(aplayer->getArea()==0) {//jika di rumah
						try {
							Save(aplayer->getName());
						}catch(int x) {
							if(x==0) {
                                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                            gotoxy(0,18); cout<< "terjadi error ketika save" << endl;
                                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
							}
						}
					}else{
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "perintah save hanya bisa dilakukan di dalam rumah" << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}
			}else if(strcmp(command,"store")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando store harus diakhiri dengan tanda pagar!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
				}
				if(aplayer->getArea()==2) {
                                    gotoxy(0,22); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,22); cout << endl;
					cout << "bibit cabai @ 10" << endl;
					cout << "bibit wortel @ 5" << endl;
					cout << "bibit jamur @ 8" << endl;
					cout << "bibit melon @ 6" << endl;
					cout << "bibit pisang @ 6" << endl;
					cout << "bibit jagung @ 7" << endl;
					cout << endl;
                                  gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
				}else{
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout << "perintah ini hanya bisa dilakukan di toko" << endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
				}
			}else if(strcmp(command,"buy")==0) {
				int zzz = 0;
				char param1[10];
				char param2[10];
				int nslot;
				ignoreBlank(tabparser, m, m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param1[z] = tabparser[m];
					m++;
					z++;
					}
				if (z != 0) {
					zzz++;
					}
				param1[z] = '\0';
				ignoreBlank(tabparser, m, m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param2[z] = tabparser[m];
					m++;
					z++;
					}
				if (z != 0) {
					zzz++;
					}
				param2[z] = '\0';
				ignoreBlank(tabparser, m, m);
				if ((tabparser[m] != '#') || (zzz <2 )) {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando buy harus diakhiri dengan tanda pagar dan harus memiliki tepat dua parameter!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else 
				{
					int code;
					int testerr = sscanf(param2,"%d",&nslot);
					if(testerr!=0){
						if (strcmp(param1,"cabai") == 0) {
							code = 1;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"wortel") == 0) {
							code = 2;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"jamur") == 0) {
							code = 3;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"melon") == 0) {
							code = 4;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"jagung") == 0) {
							code = 5;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"pisang") == 0) {
							code = 6;
							aplayer->buy(code,nslot);
						}else if (strcmp(param1,"mangga") == 0) {
							code = 7;
						}else{ 
							cout << "barang tersebut tidak ada . ." << endl;
						}
						//cout << "uang anda sekarang : " << aplayer->getMoney() << endl;
					}else
                                        {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout << "jumlah barang yang dibeli harus berupa angka" << endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}
				}
			}else if(strcmp(command,"sell")==0) {
				int zzz=0;
				char param1[10];
				char param2[10];
				int parameter1=0;
				int parameter2=0;
				ignoreBlank(tabparser, m, m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param1[z] = tabparser[m];
					m++;
					z++;
					}
				if (z != 0) {
					zzz++;
					}
				param1[z] = '\0';
				ignoreBlank(tabparser,m , m);
				z = 0;
				while ((tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
					param2[z] = tabparser[m];
					m++;
					z++;
					}
				if (z != 0) {
					zzz++;
					}
				param2[z] = '\0';
				ignoreBlank(tabparser, m, m);
				if ((tabparser[m] != '#') || (zzz<2)) {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"komando sell harus diakhiri dengan tanda pagar dan harus memiliki tepat dua parameter!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					//parameter1 = StringToInteger(param1); // nomor slot di inventory yang ingin dijual
					//parameter2 = StringToInteger(param2); // jumlah barang yang ingin dijual
					//realisasi!
					sscanf(param1,"%d",&parameter1);
					sscanf(param2,"%d",&parameter2);
					aplayer->sell(parameter1, parameter2);
					}
			}else if(strcmp(command,"eat")==0) {
				char param1[10];
				int nomor;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '#') {
                                        gotoxy(0,18); cout<< ">\t\t\t\t\t\t\t\t";
					gotoxy(0,18); cout<<"Error! komando eat harus disertai dengan parameter yaitu nomor slot inventory!"<<endl;
                                        gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					z = 0;
					cout<<endl;
					while ((tabparser[m] != ' ') && (tabparser[m] != '#') && (tabparser[m] != '\0')) {
						param1[z] = tabparser[m];
						m++;
						z++;
						}
					param1[z] = '\0';
					ignoreBlank(tabparser, m, m);
					if (tabparser[m] != '#') {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"Error! komando eat tidak boleh memiliki parameter lain selain nomor slot dan harus diakhiri dengan tanda pagar!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }else {
						sscanf(param1,"%d",&nomor);
						//eksekusi eat
                                                aplayer->eat(nomor);
					}
				}
			}else if(strcmp(command,"right")==0) {
				bool salahinput=false;
				char param1[10];
				z = 0;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '\0') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"error! komando right harus diakhiri dengan tanda pagar!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else if (tabparser[m] != '#') {
					int n = m;
					while (tabparser[n] != ' ' && tabparser[n] != '\0' && tabparser[n] != '#') {
						n++;
						}
					ignoreBlank(tabparser, n, n);
					if (tabparser[n] == '#') {
					while ((salahinput==false) && (tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
						if ((tabparser[m] != '0') && (tabparser[m] != '1') && (tabparser[m] != '2') && (tabparser[m] != '3') && (tabparser[m] != '4') && (tabparser[m] != '5') && (tabparser[m] != '6') && (tabparser[m] != '7') && (tabparser[m] != '8') && (tabparser[m] != '9')) {
							salahinput = true;
							}
						else {
							param1[z] = tabparser[m];
							m++;
							z++;
							}
						}
				if (salahinput == true) {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"error! jumlah langkah yang dimasukkan bukan integer! jumlah langkah haruslah berupa integer!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }else {
					//disini panggil fungsi yang menangani kalo berparameter
						int step=0;
						sscanf(param1,"%i",&step);
						for(int i=0;i<step;i++) {
							if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
								if((aplayer->getpos()).x < 5){
									aplayer->moveRight();
								}else{
									aplayer->turn_right();
									break;
								}
							}else if(aplayer->getArea()==1){
								if(aplayer->getFace()!=1){
									aplayer->turn_right();
								}else{
									if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
										if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
											aplayer->moveRight();
										}
									}else{
										break;
									}
								}
								akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							}
						}
					}
				}else {
					if (tabparser[n] == '\0') {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18);cout<<"error! tidak diakhiri dengan tanda pagar!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        } else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang diberikan untuk movement right seharusnya hanya satu yaitu jumlah langkah! ulangi masukkan!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";}
					}
				}else {
					if (tabparser[m] == '#') {
						//panggil fungsi yang menangani kalo tidak berparameter
						if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
							if((aplayer->getpos()).x < 5){
								aplayer->moveRight();
							}else{
								aplayer->turn_right();
							}
						}else if(aplayer->getArea()==1){
							if(aplayer->getFace()!=1){
								aplayer->turn_right();
							}else{
								if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
									if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
										aplayer->moveRight();
									}
								}
							}
							akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
						}
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang dimasukkan lebih dari satu! parameter untuk move right seharusnya hanya satu berupa banyaknya langkah!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
				}
			}else if(strcmp(command,"left")==0) {
				bool salahinput=false;
				char param1[10];
				z = 0;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '\0') {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"error! komando left harus diakhiri dengan tanda pagar!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else if (tabparser[m] != '#') {
					int n = m;
					while (tabparser[n] != ' ' && tabparser[n] != '\0' && tabparser[n] != '#') {
						n++;
						}
					ignoreBlank(tabparser, n, n);
					if (tabparser[n] == '#') {
						while ((salahinput==false) && (tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
							if ((tabparser[m] != '0') && (tabparser[m] != '1') && (tabparser[m] != '2') && (tabparser[m] != '3') && (tabparser[m] != '4') && (tabparser[m] != '5') && (tabparser[m] != '6') && (tabparser[m] != '7') && (tabparser[m] != '8') && (tabparser[m] != '9')) {
								salahinput = true;
							}else {
								param1[z] = tabparser[m];
								m++;
								z++;
							}
						}
						if (salahinput == true) {
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout<<"error! jumlah langkah yang dimasukkan bukan integer! jumlah langkah haruslah berupa integer!"<<endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }else {
							//disini panggil fungsi yang menangani kalo berparameter
							int step=0;
							sscanf(param1,"%i",&step);
							for(int i=0;i<step;i++) {
								if(aplayer->getArea()==0 || aplayer->getArea()==2) {
									if((aplayer->getpos()).x > 0) {
										aplayer->moveLeft();
									}else{
										aplayer->turn_left();
										break;
									}
								}else if(aplayer->getArea()==1) {
									if(aplayer->getFace()!=0){
										aplayer->turn_left();
									}else{
										if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
											if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
												aplayer->moveLeft();
											}
										}else {
											break;
										}
									}
									akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
									akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
									akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								}
							}
						}
					}else {
						if (tabparser[n] == '\0') {
                                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout<<"error! tidak diakhiri dengan tanda pagar!"<<endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }else {
                                                    gotoxy(0,18); cout<< ">\t\t\t\t\t\t\t\t";
                                                    gotoxy(0,18); cout<<"error! parameter yang diberikan untuk movement left seharusnya hanya satu yaitu jumlah langkah! ulangi masukkan!"<<endl;
                                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                                }
					}				
				}
				else {
					if (tabparser[m] == '#') {
					//disini eksekusi kalo cuma right left up down tanpa parameter
						if(aplayer->getArea()==0 || aplayer->getArea()==2) {
							if((aplayer->getpos()).x > 0) {
								aplayer->moveLeft();
							}else{
								aplayer->turn_left();
							}
						}else if(aplayer->getArea()==1) {
							if(aplayer->getFace()!=0){
								aplayer->turn_left();
							}else{
								if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
									if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
										aplayer->moveLeft();
									}
								}
							}
							akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
						}
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang dimasukkan lebih dari satu! parameter untuk move left seharusnya hanya satu berupa banyaknya langkah!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                            }
					}
			
			}else if(strcmp(command,"up")==0) {
				bool salahinput=false;
				char param1[10];
				z = 0;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '\0') {
                                        gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                        gotoxy(0,18); cout<<"error! komando up harus diakhiri dengan tanda pagar!"<<endl;
                                        gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else if (tabparser[m] != '#') {
					int n = m;
					while (tabparser[n] != ' ' && tabparser[n] != '\0' && tabparser[n] != '#') {
						n++;
						}
					ignoreBlank(tabparser, n, n);
					if (tabparser[n] == '#') {
					while ((salahinput==false) && (tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
						if ((tabparser[m] != '0') && (tabparser[m] != '1') && (tabparser[m] != '2') && (tabparser[m] != '3') && (tabparser[m] != '4') && (tabparser[m] != '5') && (tabparser[m] != '6') && (tabparser[m] != '7') && (tabparser[m] != '8') && (tabparser[m] != '9')) {
							salahinput = true;
							}
						else {
							param1[z] = tabparser[m];
							m++;
							z++;
							}
						}
				if (salahinput == true) {
                                        gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
					gotoxy(0,18); cout<<"error! jumlah langkah yang dimasukkan bukan integer! jumlah langkah haruslah berupa integer!"<<endl;
					gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					//disini panggil fungsi yang menangani kalo berparameter
						int step=0;
						sscanf(param1,"%i",&step);
						for(int i=0;i<step;i++) {
							if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
								if((aplayer->getpos()).y > 0) {
									aplayer->moveUp();
								}else{
									aplayer->turn_up();
									break;
								}
							}else if(aplayer->getArea()==1) {//jika lahan
								if(aplayer->getFace()!=2){
									aplayer->turn_up();
								}else{
									if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
										if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
											aplayer->moveUp();
										}
									}else{
										break;
									}
								}
								akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							}
						}
					}
				}else {
					if (tabparser[n] == '\0') {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! tidak diakhiri dengan tanda pagar!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
					else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang diberikan untuk movement up seharusnya hanya satu yaitu jumlah langkah! ulangi masukkan!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
                                    }
				
				}
				else {
					if (tabparser[m] == '#') {
					//disini eksekusi kalo cuma up tanpa parameter
						if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
							if((aplayer->getpos()).y > 0)
								aplayer->moveUp();
							else
								aplayer->turn_up();
						}else if(aplayer->getArea()==1) {//jika lahan
							if(aplayer->getFace()!=2){
								aplayer->turn_up();
							}else{
								if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
									if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
										aplayer->moveUp();
									}
								}
							}
							akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
						}
					}
					else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang dimasukkan lebih dari satu! parameter untuk move up seharusnya hanya satu berupa banyaknya langkah!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                        }
                                    }
			
			}else if(strcmp(command,"down")==0) {
				bool salahinput=false;
				char param1[10];
				z = 0;
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] == '\0') {
                                                gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
						gotoxy(0,18); cout<<"error! komando down harus diakhiri dengan tanda pagar!"<<endl;
						gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else if (tabparser[m] != '#') {
					int n = m;
					while (tabparser[n] != ' ' && tabparser[n] != '\0' && tabparser[n] != '#') {
						n++;
						}
					ignoreBlank(tabparser, n, n);
					if (tabparser[n] == '#') {
					while ((salahinput==false) && (tabparser[m] != ' ') && (tabparser[m] != '\0') && (tabparser[m] != '#')) {
						if ((tabparser[m] != '0') && (tabparser[m] != '1') && (tabparser[m] != '2') && (tabparser[m] != '3') && (tabparser[m] != '4') && (tabparser[m] != '5') && (tabparser[m] != '6') && (tabparser[m] != '7') && (tabparser[m] != '8') && (tabparser[m] != '9')) {
							salahinput = true;
							}
						else {
							param1[z] = tabparser[m];
							m++;
							z++;
							}
						}
				if (salahinput == true) {
                                    gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                    gotoxy(0,18); cout<<"error! jumlah langkah yang dimasukkan bukan integer! jumlah langkah haruslah berupa integer!"<<endl;
                                    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					//disini panggil fungsi yang menangani kalo berparameter
						int step=0;
						sscanf(param1,"%i",&step);
						for(int i=0;i<step;i++) {
							if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
								if((aplayer->getpos()).y < 5) {
									aplayer->moveDown();
								}else{
									aplayer->turn_down();
									break;
								}
							}else if(aplayer->getArea()==1){
								if(aplayer->getFace()!=3){
									aplayer->turn_down();
								}else{
									if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
										if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
											aplayer->moveDown();
										}
									}else {
										break;
									}
								}
								akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
								akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							}
						}
					}
					}
				else {
					if (tabparser[n] == '\0') {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! tidak diakhiri dengan tanda pagar!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang diberikan untuk movement down seharusnya hanya satu yaitu jumlah langkah! ulangi masukkan!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";}
					}
				}
				else {
					if (tabparser[m] == '#') {
					//disini eksekusi kalo cuma right left up down tanpa parameter
						if(aplayer->getArea()==0 || aplayer->getArea()==2){ //kalo rumah ato shop
							if((aplayer->getpos()).y < 5) {
								aplayer->moveDown();
							}else{
								aplayer->turn_down();
							}
						}else if(aplayer->getArea()==1){
							if(aplayer->getFace()!=3){
								aplayer->turn_down();
							}else{
								if(afield->IsWalkable(aplayer->getvektor().x,aplayer->getvektor().y)) {	
									if((akurcharvest->getpos().x!=aplayer->getvektor().x || akurcharvest->getpos().y!=aplayer->getvektor().y) && (akurcwater->getpos().x!=aplayer->getvektor().x || akurcwater->getpos().y!=aplayer->getvektor().y) && (akurcslash->getpos().x!=aplayer->getvektor().x || akurcslash->getpos().y!=aplayer->getvektor().y)) {
										aplayer->moveDown();
									}
								}
							}
							akurcwater->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcharvest->walk(aplayer,afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
							akurcslash->walk(afield,aplayer->getpos().x,aplayer->getpos().y,akurcwater->GetX(),akurcwater->GetY(),akurcharvest->GetX(),akurcharvest->GetY(),akurcslash->GetX(),akurcslash->GetY());
						}
					}else {
                                            gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
                                            gotoxy(0,18); cout<<"error! parameter yang dimasukkan lebih dari satu! parameter untuk move up seharusnya hanya satu berupa banyaknya langkah!"<<endl;
                                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";}
					}
			
			}else if(strcmp(command,"help")==0) {
				ignoreBlank(tabparser, m, m);
				if (tabparser[m] != '#') {
                                        gotoxy(0,18); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
					gotoxy(0,18); cout<<"komando untuk meminta bantuan harus diakhiri dengan tanda pagar! Tidak boleh memiliki parameter apapun!"<<endl;
					gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
                                }
				else {
					//eksekusi komando help
					//mengawali permainan
					cout<<"*****mengawali permainan*****"<<endl;
					cout<<"new <nama_pemain> # 		: mengawali permainan dengan pemain yang baru"<<endl;
					cout<<"load <nama_file> # 		: me-load permainan yang save date bernama <nama_file>"<<endl;
					//pemain
					cout<<"*****pemain******"<<endl;
					cout<<"<right|left|up|down> <langkah> # : menggerakkan pemain ke 1 arah sebanyak <langkah>"<<endl;
					cout<<"inventory #			: menampilkan daftar barang yang ada di ransel"<<endl;
					cout<<"teleport <nama_area> #		: berpindah dari satu tempat ke tempat yang lain"<<endl;
					cout<<"teleport -help #                 : informasi tempat yang bisa dicapai dari current_area"<<endl;
					//buat di lahan
					cout<<"*****hanya bisa dilakukan di lahan*****"<<endl;
					cout<<"plow #				: mencangkul lahan tepat di hadapan pemain"<<endl;
					cout<<"put <nomor_slot> #		: menanam/membuang/menjual barang di slot <nomor_slot>"<<endl;
					cout<<"slash #				: menyabit lahan tepat di hadapan pemain"<<endl;
					cout<<"water #				: menyiram tanaman tepat di hadapan pemain"<<endl;
					cout<<"harvest #			: memanen tanaman tepat di hadapan pemain yang telah mencapai masa panen"<<endl;
					cout<<"put <nomor_slot> <jumlah> #	: menanam/membuang/menjual barang di slot <nomor_slot> * <jumlah>"<<endl;
					cout<<"**********kurcaci**********"<<endl;
					cout<<"wake_up <nomor_kurcaci> #	: membangunkan kurcaci ke-<nomor_kurcaci> untuk bekerja"<<endl;
					cout<<"sleep <nomor_kurcaci> #		: menidurkan kurcaci ke-<nomor_kurcaci>"<<endl;
					cout<<"status kurcaci #			: menampilkan status kurcaci"<<endl;
					//di rumah
					cout<<"*****hanya bisa dilakukan di rumah*****"<<endl;
					cout<<"sleep #				: menidurkan pemain dan bangun di keesokan harinya"<<endl;
					cout<<"save #				: menyimpan permainan"<<endl;
					cout<<"exit #				: keluar dari permainan"<<endl;
					//di toko
					cout<<"*****hanya bisa dilakukan di toko"<<endl;
					cout<<"store #				: melihat daftar bibit yang dapat dibeli"<<endl;
					cout<<"buy <nama_item> <jumlah> #	: membeli bibit <nama_item> sejumlah <jumlah>"<<endl;
					cout<<"sell <nomor_slot> <jumlah> #	: menjual barang yang ada di <nomor_slot> sebanyak <jumlah>"<<endl;
				}
			}else {
                            gotoxy(0,18); cout<< ">\t\t\t\t\t\t\t\t";
                            gotoxy(0,18); cout<<"Komando tidak dikenali! Silakan ketik \"help #\" untuk menu bantuan"<<endl;
                            gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; gotoxy(0,17); cout<< ">";
			}
		}
    }
	if(init==true && aplayer->getAP()<=0) {//mekanisme ganti hari
		//gotoxy(20,5); cout << "kamu tertidur . . ." << endl;
		Kalendar::NextHari();
		aplayer->setArea(0);//pindah otomatis ke rumah
		aplayer->setpos(0,0);
		akurcharvest->SetX(10);
		akurcharvest->SetY(0);
		akurcharvest->setFace(3);
		akurcharvest->Sleep();
		akurcwater->SetX(11);
		akurcwater->SetY(0);
		akurcwater->setFace(3);
		akurcwater->Sleep();
		akurcslash->SetX(12);
		akurcslash->SetY(0);
		akurcslash->setFace(3);
		akurcslash->Sleep();
		/*cout << "Hari : " <<  Kalendar::GetHari() << " , ";
		if(Kalendar::GetMusim()==0) {
			cout << "Musim : Kemarau" << endl;
		}else{
			cout << "Musim : Hujan" << endl;
		}*/
		afield->GrowAllPlant();
		int temp = Kalendar::RandomizeEvent();
		if(temp==0) {
			//kejadian tornado
			afield->DieAllPlant();
		}else if(temp==1) {
			//kejadian hujan
			afield->WaterAllPlant();
		}else if(temp==2) {
			//tidak ada kejadian
		}
		aplayer->setAP(aplayer->getMAXAP());
	}
	
}

void Parser::New(string nama) {
	ifstream exfile;
	string nama_file;
	nama_file = nama + ".txt";
	nama_file = "save/" + nama_file;
	ifstream myfile;
	exfile.open(nama_file.c_str());
	if(exfile.is_open()) {//jika sudah ada data player dengan nama yang sama sebelomnya tampilkan error 0
		throw 0;
		exfile.close();
	}
	cout << "memulai permainan baru" << endl;
	cout << "anda bernama " << nama << endl;
	
	init = true;
	aplayer = new player();
	akurcharvest = new KurcaciHarvest();
	akurcwater = new KurcaciWater();
	akurcslash = new KurcaciSlash();
	
	aplayer->setName(nama);
	aplayer->setMoney(300);//default money 300
	aplayer->setArea(0);//default muncul di home
	aplayer->setpos(0,0);
	aplayer->setFace(3);
	cout << aplayer->getMoney() << endl;
	
	akurcharvest->setpos(10,0);
	akurcharvest->setFace(3);
	akurcharvest->Sleep();
	akurcwater->setpos(11,0);
	akurcwater->setFace(3);
	akurcwater->Sleep();
	akurcslash->setpos(12,0);
	akurcslash->setFace(3);
	akurcslash->Sleep();
	
	afield = new field();
	ashop = new shop();
	ahouse = new house();
	Cabai * cb =  new Cabai();
	cb->SetHappyMeter(0);
	afield->DeleteObject(1,1);
	afield->InsertObject(cb,1,1);
	Mangga * mg =  new Mangga();
	mg->SetHappyMeter(0);
	afield->DeleteObject(1,2);
	afield->InsertObject(mg,1,2);
	afield->DeleteObject(1,3);
	Jamur * j =  new Jamur();
	j->SetHappyMeter(10);
	afield->InsertObject(j,1,3);
	Pisang * p = new Pisang();
	p->SetUmur(0);
	afield->DeleteObject(1,4);
	afield->InsertObject(p,1,4);
	
	cout << "anda sedang berada di rumah . . ." << endl;
	cout << "Hari : " <<  Kalendar::GetHari() << " , ";
	if(Kalendar::GetMusim()==0) {
		cout << "Musim : Kemarau" << endl;
	}else{
		cout << "Musim : Hujan" << endl;
	}
        system("cls");
	ahouse->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),0,0,0,0,0,0,0,0,0); printStatus();
}

void Parser::Load(string nama_file) {
	nama_file+=".txt";
	nama_file = "save/" + nama_file;
	ifstream myfile;
	myfile.open(nama_file.c_str());
	if (!myfile.is_open())
	{
		throw 0;
	}
	int money_player;
	int action_point;
	string nama_player;
	int face;
	
	int id_barang_slot1;
	int jumlah_slot1;
	int id_barang_slot2;
	int jumlah_slot2;
	int id_barang_slot3;
	int jumlah_slot3;
	
	int jenis_objek;
	
	bool isplowed;
	bool isnonplantable;
	bool issellingspot;
	
	int jenis_tanaman;
	int umur;
	bool iswatered;
	int happymeter;
	int tingkat_panen;
	
	bool nonplantable;
	bool isplow;
	bool sellingspot;
	
	int musim;
	int hari;
	
	if (myfile.is_open())
	{
		init = true;
		
		afield = new field();
		ashop = new shop();
		ahouse = new house();
		aplayer = new player();
		akurcharvest = new KurcaciHarvest();
		akurcwater = new KurcaciWater();
		akurcslash = new KurcaciSlash();
		
		myfile >> money_player;
		myfile >> action_point;
		myfile >> nama_player;
		
		myfile >> id_barang_slot1;
		myfile >> jumlah_slot1;
		myfile >> id_barang_slot2;
		myfile >> jumlah_slot2;
		myfile >> id_barang_slot3;
		myfile >> jumlah_slot3;
		if(id_barang_slot1!=-1) {
			aplayer->setInventory(1,id_barang_slot1,jumlah_slot1);
		}
		if(id_barang_slot2!=-1) {
			aplayer->setInventory(2,id_barang_slot2,jumlah_slot2);
		}
		if(id_barang_slot3!=-1) {
			aplayer->setInventory(3,id_barang_slot3,jumlah_slot3);
		}
		for (int i=0;i<13;i++)
		{	
			for (int j=0;j<13;j++)
			{
				myfile >> jenis_objek;
				if (jenis_objek==0)
				{
					myfile >> isplowed;
					myfile >> isnonplantable;
					myfile >> issellingspot;
					afield->InsertObject(new Tanah(isplowed,isnonplantable,issellingspot),j,i);
				}else if (jenis_objek==1)
				{
					myfile >> jenis_tanaman;
					myfile >> umur;
					myfile >> iswatered;
					myfile >> happymeter;
					myfile >> tingkat_panen;
					if(jenis_tanaman==0) {
						afield->InsertObject(new Cabai(),j,i);
					}else if(jenis_tanaman==1) {
						afield->InsertObject(new Mangga(),j,i);
					}else if(jenis_tanaman==2) {
						afield->InsertObject(new Wortel(),j,i);
					}else if(jenis_tanaman==3) {
						afield->InsertObject(new Jamur(),j,i);
					}else if(jenis_tanaman==4) {
						afield->InsertObject(new Melon(),j,i);
					}else if(jenis_tanaman==5) {
						afield->InsertObject(new Pisang(),j,i);
					}else if(jenis_tanaman==6) {
						afield->InsertObject(new Jagung(),j,i);
					}
					dynamic_cast<Plant*>(afield->getObject(j,i))->SetUmur(umur);
					dynamic_cast<Plant*>(afield->getObject(j,i))->SetHappyMeter(happymeter);
					dynamic_cast<Plant*>(afield->getObject(j,i))->SetWatered(iswatered);
					dynamic_cast<Plant*>(afield->getObject(j,i))->SetTingkatPanen(tingkat_panen);
				}
			}
		}
		myfile >> musim;
		myfile >> hari;
		
		aplayer->setName(nama_player);
		aplayer->setMoney(money_player);
		aplayer->setArea(0);//default muncul di home
		aplayer->setpos(0,0);
		aplayer->setFace(3);
		
		akurcharvest->setpos(10,0);
		akurcharvest->setFace(3);
		akurcharvest->Sleep();
		akurcwater->setpos(11,0);
		akurcwater->setFace(3);
		akurcwater->Sleep();
		akurcslash->setpos(12,0);
		akurcslash->setFace(3);
		akurcslash->Sleep();
		
		Kalendar::SetMusim(musim);
		Kalendar::SetHari(hari);
	}
	myfile.close();
	cout << "anda sedang berada di rumah . . ." << endl;
	cout << "Hari : " <<  Kalendar::GetHari() << " , ";
	if(Kalendar::GetMusim()==0) {
		cout << "Musim : Kemarau" << endl;
	}else{
		cout << "Musim : Hujan" << endl;
	}
        system("cls");
	ahouse->Display((aplayer->getpos()).x,(aplayer->getpos()).y,aplayer->getFace(),0,0,0,0,0,0,0,0,0); printStatus();
}

void Parser::Save(string nama_file) {
	nama_file+=".txt";
	nama_file = "save/" + nama_file;
	ofstream myfile;
	myfile.open(nama_file.c_str(),ios::trunc);
	if (!myfile.is_open())
	{
		throw 0;
	}
	if(myfile.is_open()) {
		myfile << aplayer->getMoney() << " " << aplayer->getAP() << " " << aplayer->getName() << endl;
		if(aplayer->isInvEmpty(1)) {
			myfile << "-1 0" << endl;
		}else{
			if((aplayer->getInvAt(1))->getObjectType()==4) { //jika buah	
				myfile << dynamic_cast<Fruit*>(aplayer->getInvAt(1))->GetFruit_id() << " " << aplayer->getInvSize(1) << endl;
			}else if((aplayer->getInvAt(1))->getObjectType()==5) {//jika bibit
				myfile << dynamic_cast<Bibit*>(aplayer->getInvAt(1))->getBibitId() << " " << aplayer->getInvSize(1) << endl;
			}
		}
		if(aplayer->isInvEmpty(2)) {
			myfile << "-1 0" << endl;
		}else{
			if((aplayer->getInvAt(1))->getObjectType()==4) {//jika buah	
				myfile << dynamic_cast<Fruit*>(aplayer->getInvAt(2))->GetFruit_id() << " " << aplayer->getInvSize(2) << endl;
			}else if((aplayer->getInvAt(1))->getObjectType()==5) {//jika bibit
				myfile << dynamic_cast<Bibit*>(aplayer->getInvAt(2))->getBibitId() << " " << aplayer->getInvSize(2) << endl;
			}
		}
		if(aplayer->isInvEmpty(3)) {
			myfile << "-1 0" << endl;
		}else{
			if((aplayer->getInvAt(1))->getObjectType()==4) {//jika buah	
				myfile << dynamic_cast<Fruit*>(aplayer->getInvAt(3))->GetFruit_id() << " " << aplayer->getInvSize(3) << endl;
			}else if((aplayer->getInvAt(1))->getObjectType()==5) {//jika bibit
				myfile << dynamic_cast<Bibit*>(aplayer->getInvAt(3))->getBibitId() << " " << aplayer->getInvSize(3) << endl;
			}
		}
		for(int i=0;i<13;i++) {
			for(int j=0;j<13;j++) {
				if((afield->getObject(j,i))->getObjectType() == 0) {//jika tanah
					myfile << "0 " << dynamic_cast<Tanah*>(afield->getObject(j,i))->isPlowed() << " " << dynamic_cast<Tanah*>(afield->getObject(j,i))->isNonPlantable() << " " << dynamic_cast<Tanah*>(afield->getObject(j,i))->isSellingSpot() << endl;
				}else if((afield->getObject(j,i))->getObjectType() == 3){
					myfile << "1 " << dynamic_cast<Plant*>(afield->getObject(j,i))->GetPlantId() << " " << dynamic_cast<Plant*>(afield->getObject(j,i))->GetUmur() << " " << dynamic_cast<Plant*>(afield->getObject(j,i))->isWatered() << " " << dynamic_cast<Plant*>(afield->getObject(j,i))->GetHappyMeter() << " " << dynamic_cast<Plant*>(afield->getObject(j,i))->GetTingkatPanen() << endl;
				}
			}
		}
		myfile << Kalendar::GetMusim() << " " << Kalendar::GetHari() << endl;
	}
	myfile.close();
}

int Parser::StringToInteger(char konversi[]) {
	/*
	double length = 0;
	while ((konversi[length] != '\0') && (konversi[length] != ' ') && (konversi[length] != '#')) {
		length++;
		}
	int hasil = 0;
	int i = 0;
	while (length > 0) {
		hasil += konversi[i] * pow(10, (length-1));
		length--;
		i++;
		}
	return hasil;
	*/
}
	
void Parser::printStatus()
{
    gotoxy(40,0); cout<< "Name\t: " << aplayer->getName() << endl;
    gotoxy(40,1); cout<< "\t\t          ";
    gotoxy(40,1); cout<< "AP\t: " << aplayer->getAP() << endl;
    gotoxy(40,2); cout<< "\t\t          ";
    gotoxy(40,2); cout<< "Money\t: " << aplayer->getMoney() << endl;
    gotoxy(40,4); cout<< "\t\t          ";
    gotoxy(40,4); cout<< "Hari " << Kalendar::GetHari() << " ";
    if (Kalendar::GetMusim() == 0) cout<< "Musim Kemarau\n";
    else if (Kalendar::GetMusim() == 1) cout<< "Musim Hujan\n";
    gotoxy(40,5); cout<< "\t\t\t\t\t\t";
    gotoxy(40,5); cout<< "Kurcaci Water\t: "; akurcwater->GetStatusSleep()? cout<< "sleep\n": cout<< "wake up\n";
    gotoxy(40,6); cout<< "\t\t\t\t\t\t";
    gotoxy(40,6); cout<< "Kurcaci Harvest\t: "; akurcharvest->GetStatusSleep()? cout<< "sleep\n": cout<< "wake up\n";
    gotoxy(40,7); cout<< "\t\t\t\t\t\t";
    gotoxy(40,7); cout<< "Kurcaci Slash\t: "; akurcslash->GetStatusSleep()? cout<< "sleep\n": cout<< "wake up\n";
    gotoxy(40,9); cout<< "\t\t\t\t\t\t";
    gotoxy(40,10); cout<< "\t\t\t\t\t\t";
    gotoxy(40,11); cout<< "\t\t\t\t\t\t";
    for (int y = 16; y<= 55; y++)
    {
        gotoxy(0,y); cout<< "\t\t\t\t\t\t\t\t\t\t\t\t\t";
    }
    gotoxy(0,17); cout<< "\t\t\t\t\t\t\t\t"; 
    gotoxy(0,17); cout<< ">";
}